# 尝试导入分析器，但允许失败
try:
    from .hikyuu_analyzer import HikyuuAnalyzer
    HIKYUU_AVAILABLE = True
except ImportError:
    print("警告: Hikyuu分析器不可用，将使用简化版分析器")
    HIKYUU_AVAILABLE = False
    # 创建一个简化的替代分析器
    class SimpleAnalyzer:
        def __init__(self, config):
            self.config = config
            
        def analyze_stock(self, stock_code):
            return {
                'stock_code': stock_code,
                'summary': '分析器未安装',
                'confidence': 'low',
                'message': '请安装hikyuu以获取完整分析功能'
            }
            
        def backtest(self, stock_code, start_date=None, end_date=None, strategy='ma_cross'):
            return {
                'summary': {
                    'stock': stock_code,
                    'strategy': strategy,
                    'message': '无法执行回测，请安装hikyuu'
                }
            }
    
    HikyuuAnalyzer = SimpleAnalyzer

try:
    from .qlib_analyzer import QlibAnalyzer
    QLIB_AVAILABLE = True
except ImportError:
    print("警告: Qlib分析器不可用")
    QLIB_AVAILABLE = False
    QlibAnalyzer = None

class QuantAnalyzerFactory:
    """量化分析工厂类，用于选择和创建不同的量化分析器"""
    
    def __init__(self, config):
        self.config = config
        self.analyzers = {}
        
    def get_analyzer(self, analyzer_type):
        """获取指定类型的分析器实例"""
        if analyzer_type in self.analyzers:
            return self.analyzers[analyzer_type]
        
        if analyzer_type == 'qlib' and QLIB_AVAILABLE:
            analyzer = QlibAnalyzer(self.config.get('qlib', {}))
            self.analyzers[analyzer_type] = analyzer
            return analyzer
        
        # 默认使用hikyuu或它的替代
        analyzer = HikyuuAnalyzer(self.config.get('hikyuu', {}))
        self.analyzers['hikyuu'] = analyzer
        return analyzer 